home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XAAES_S.ZIP / XAAES / SHELL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-03  |  2.4 KB  |  123 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <OSBIND.H>
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include "k_defs.h"
  13. #include "xa_globl.h"
  14. #include "shellwrt.h"
  15. #include "xa_defs.h"
  16.  
  17. unsigned long XA_shell_write(short clnt_pid, AESPB *pb)
  18. {
  19.     XA_CLIENT *client=Pid2Client(clnt_pid),*child;
  20.     short child_id;
  21.     
  22.     child_id=shell_write(pb->intin[0],pb->intin[1],pb->intin[2],(char*)pb->addrin[0],(char*)pb->addrin[1]);
  23.     pb->intout[0]=child_id;
  24.     
  25.     child=Pid2Client(child_id);
  26.     child->parent=clnt_pid;
  27.     
  28.     if ((pb->intin[0]==1)&&(pb->intin[1]==1))
  29.     {
  30.         client->waiting_for=XAWAIT_CHILD;
  31.         return XAC_BLOCK;
  32.     }
  33.     
  34.     return XAC_DONE;
  35. }
  36.  
  37. unsigned long XA_shell_read(short clnt_pid, AESPB *pb)
  38. {
  39.     char *parent_name=(char*)pb->addrin[0];
  40.     char *tail=(char*)pb->addrin[1];
  41.     short f;
  42.     
  43.     sprintf(parent_name, "%s",clients[clients[clnt_pid].parent].cmd_name);
  44.     
  45.     for(f=0; f<clients[clnt_pid].cmd_tail[0]+1; f++)
  46.         tail[f]=clients[clnt_pid].cmd_tail[f];
  47.     tail[f]=0;
  48.     
  49.     pb->intout[0]=1;
  50.     
  51.     return XAC_DONE;
  52. }
  53.  
  54. unsigned long XA_shell_find(short clnt_pid, AESPB *pb)
  55. {
  56.     char *kp=getenv("PATH");
  57.     char *fn=pb->addrin[0];
  58.     char path[128],cwd[200];
  59.     long handle;
  60.     short f=0,l,n;
  61.     
  62. /* check the clients home path */
  63.     sprintf(path,"%s\\%s",clients[clnt_pid].home_path,fn);
  64.     handle=Fopen(path,0);
  65.     if (handle>0)
  66.     {
  67.         Fclose(handle);
  68.         sprintf(fn,"%s",path);
  69.         pb->intout[0]=1;
  70.         
  71.         return XAC_DONE;
  72.     }
  73.     
  74. /* check our PATH enviroment variable */
  75.     l=strlen(cwd);
  76.     sprintf(cwd,"%s",kp);
  77.     
  78.     while(f<l)
  79.     {                /* We understand ':', ';' and ',' as path seperators */
  80.         for(n=f; (cwd[n])&&(cwd[n]!=':')&&(cwd[n]!=';')&&(cwd[n]!=','); n++)
  81.             if (cwd[n]=='/') cwd[n]='\\';
  82.         
  83.         cwd[n]='\0';
  84.         
  85.         sprintf(path,"%s\\%s",cwd+f,fn);
  86.         handle=Fopen(path,0);
  87.         if (handle>0)
  88.         {
  89.             Fclose(handle);
  90.             sprintf(fn,"%s",path);
  91.             pb->intout[0]=1;
  92.  
  93.             return XAC_DONE;
  94.         }
  95.         f=n+1;
  96.     }
  97.  
  98. /* Last ditch - try the file spec on it's own */
  99.     handle=Fopen(fn,0);
  100.     if (handle>0)
  101.     {
  102.         Fclose(handle);
  103.         pb->intout[0]=1;
  104.         
  105.         return XAC_DONE;
  106.     }
  107.  
  108. /* Didn't find the file :( */
  109.     pb->intout[0]=0;
  110.     return XAC_DONE;
  111. }
  112.  
  113. unsigned long XA_shell_envrn(short clnt_pid, AESPB *pb)
  114. {
  115.     char **p=pb->addrin[0];
  116.     char *name=(char*)pb->addrin[1];
  117.     *p=getenv(name);
  118.     
  119.     pb->intout[0]=1;
  120.     
  121.     return XAC_DONE;
  122. }
  123.